from syslogd.enums.Function import FunctionDict
from syslogd.enums.Priority import PriorityDict
from syslogd.enums.Selector import SelectorDict
from syslogd.Utils import Utils


class Rule(object):
    
    def __init__(self, functions, modifier, priority):
        self.functions = self.normalizeFunctions(functions)
        self.modifier = SelectorDict.get(modifier)
        self.priority = PriorityDict.get(priority)
 
    def normalizeFunctions(self, functions):
        funcs = []
        for el in functions:
            funcs.append(FunctionDict.get(el))
        return funcs

    def __str__(self):
        functions = ''
        for f in self.functions:
            functions += f + ','
        if functions.endswith(','):
            functions = functions[:-1]
        return functions + "." + \
               Utils.iif(self.modifier == None, '', self.modifier) + \
               self.priority